/**
 * FileName: UserRealm Author:   zeroleavebaoyang Date:     2018/8/28 16:45 Description:
 */
package com.shiro.sso.demo.realm;

import com.shiro.sso.demo.config.properties.AuthProperties;
import com.shiro.sso.demo.utils.Constant;
import java.util.HashSet;
import java.util.Set;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.authz.SimpleAuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;

public class UserRealm extends AuthorizingRealm {


    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
        SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo();
        Set<String> pers = new HashSet<String>();
        pers.add("user:*");
        pers.add("role:*");
        authorizationInfo.setStringPermissions(pers);
        return authorizationInfo;
    }

    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token)
            throws AuthenticationException {
        String username = (String) token.getPrincipal();
        String password = new String((char[]) token.getCredentials());
        // 从数据库中查询
        SimpleAuthenticationInfo info = new SimpleAuthenticationInfo("admin", "admin",
                getName());
        return info;
    }
}
